<script>
	function setFilter() {
      document.forms["list-form"].submit();
    }
    function search(){
        var id = document.getElementById("userId").value;
        document.location.href = "/cs/userLogs/" + id;
    }
</script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-1.9.1.js">
</script>
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js">
</script>
<script src="/static/js/exporting.js">
</script>
<script content="text/html; charset=utf-8">
            var tableToExcel = (function(){
                var uri = 'data:application/vnd.ms-excel;base64,', template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>', base64 = function(s){
                    return window.btoa(unescape(encodeURIComponent(s)))
                }, format = function(s, c){
                    return s.replace(/{(\w+)}/g, function(m, p){
                        return c[p];
                    })
                }
                return function(table, name, filename){
                    if (!table.nodeType) 
                        table = document.getElementById(table)
                    var ctx = {
                        worksheet: name || 'Worksheet',
                        table: table.innerHTML
                    }
                    document.getElementById("dlink").href = uri + base64(format(template, ctx));
                    document.getElementById("dlink").download = filename;
                    document.getElementById("dlink").click();
                }
            })()
</script>
<script type="text/javascript">
    $(document).ready(function(){
        var oDate = {
            from: ''
        };
        
        var dates = $("#from, #to ").datepicker({
            prevText: 'Prev Month',
            nextText: 'Next Month',
            monthNames: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
            monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
            dayNames: ['日','月','火','水','木','金','土'],
            dayNamesShort: ['日','月','火','水','木','金','土'],
            dayNamesMin: ['日','月','火','水','木','金','土'],
            dateFormat: 'yy-mm-dd',
            showMonthAfterYear: true,
            yearSuffix: 'Year',
            onSelect: function(selectedDate){
                oDate[this.id] = selectedDate;
                var option = this.id == "from" ? "minDate" : "maxDate", instance = $(this).data("datepicker"), date = $.datepicker.parseDate(instance.settings.dateFormat ||
                $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
                dates.not(this).datepicker("option", option, date);
            }
        });
    });
</script>
<style>
#server-status {
	text-align: center;
}

.results1 {
	float: left;
	width: 95%;
	margin-left: 30px;
	margin-right: 30px;
	margin-top: 5px;
}

td,th {
	text-align: center;
}
</style>
{% include '/templates/cs_header.html' %}
<!-- Container -->
<div id="container1">
  <!-- Content -->
  <div id="content1" class="flex">
    <div>
      <h3>사용자 로그</h3>
      <div id="user-logs">
        <div style="margin-left: 30px;">
        <form id="search-form" onsubmit="return(search());" action="" method="post">
          <h4>
            앱 ID : <label style="width: 300px;"> </label> <input type="text" id="userId" value="{{userId}}" /> <img src="/static/img/search1.png" onclick="search()" style="cursor: pointer;" />
          </h4>
        </form>
        </div>
        <div class="module1" id="changelist">
          <form id="list-form" onsubmit="return(setFilter());" action="" method="post">
            <div style="margin-left:30px;">
              <select name="actions" id="id_actions" selected={{selectedAction}}>
                  <option value="-1" >-------all--------</option>
                  {% for action in actions %}
                    {% if selectedAction == loop.index-1 %}
                      <option value="{{loop.index-1}}" selected>{{action}}</option>
                    {% else %}
                      <option value="{{loop.index-1}}">{{action}}</option>
                    {% endif %}
                  {% endfor %}
              </select>
              <input id="from" name="fromDay" style="width: 90px;" type="text" value="{{fromDay}}"/>이전 로그만 보기 
              <input type="submit" name="filter" value="filter"/>
            </div>
            <div class="results1">
              <table class="result_list">
                <thead>
                  <tr>
                    <th class="sortable" scope="col" style="width: 120px; text-align: center;">
                      <div class="text">로그 기록 시간</div>
                    </th>
                    <th class="sortable" scope="col" style="width: 40px; text-align: center;">
                      <div class="text">아이디</div>
                    </th>
                    <th class="sortable" scope="col" style="width: 100px; text-align: center;">
                      <div class="text">분류</div>
                    </th>
                    <th class="sortable" scope="col" style="text-align: center;">
                      <div class="text">상세내역</div>
                    </th>
                  </tr>
                </thead>
                <tbody>
                  {% for userLog in userLogs %}
                  <tr class="row{{ userLog.index % 2 }}">
                    <td>{{userLog.created_at}}</td>
                    <td>{{userLog.id}}</td>
                    <td>{{userLog.action}}</td>
                    <td>{{userLog.log}}</td>
                  </tr>
                  {% endfor %}
                </tbody>
              </table>
              <input type='hidden' name='cursor' value='{{cursor}}' />
              <input type='hidden' name='reversed' value='{{reversed}}' />
              <input type='hidden' name='count' value='{{count}}' />
              {% if prev %}
              <input type="submit" value="이전페이지" style="cursor: pointer;" name="_prev" />
              {% else %}
              <input type="submit" value="이전페이지" disabled name="_prev" />
              {% endif %}
              |
              {% if next %}
              <input type="submit" value="다음페이지" style="cursor: pointer;" name="_next" />
              {% else %}
              <input type="submit" value="다음페이지" disabled name="_next" />
              {% endif %}
            </div>
            <a id="dlink" style="display:none;"></a>
                &nbsp;&nbsp;&nbsp;&nbsp;<img src="/static/img/exportbtn.png" onclick="tableToExcel('exportTable', 'ユーザーログ', 'history_{{uuid}}.xls')" istyle="cursor:pointer;"/>
                <table id="exportTable" style="display:none;">
                  <tr>
                      <th>No.</th>
                      <th>ID</th>
                      <th>기록시각</th>
                      <th>구분</th>
                      <th>로그</th>
                  </tr>
                  {% for userLog in userLogs %}
                  <tr>
                      <td>{{userLog.index}}</td>
                      <td>{{userLog.id}}</td>
                      <td>{{userLog.created_at}}</td>
                      <td>{{userLog.action}}</td>
                      <td>{{userLog.log}}</td>
                  </tr>
                  {% endfor %}
              </table>
          </form>
        </div>
      </div>
    </div>
  </div>
  {% include '/templates/cs_footer.html' %}